// 两个数组arr1，arr2, arr1中存在的arr2的项按照顺序输出，不存在的按照升序放最后
/**
 *  解决思路：1。先对arr1排序，然后利用双指针依次比较 
 *           2。先要找到j,再从j开始找k!!!!!!!!
 */ 

let arr1 = [2,4,5,3,2,2,8,7,1,1,4]
let arr2 = [2,3,1,4]

let result = []
let leave = []
let arr2Map = {}

for (let i in arr1) {
  const value = arr1[i]
  if (arr2.includes(value)) {
    if (arr2Map[value]) {
      arr2Map[value] += 1 
    } else {
      arr2Map[value] = 1
    }
  } else {
    leave.push(value)
  }
}

console.log(leave, arr2Map);
for (let i in arr2) {
  const value = arr2[i]
  if(arr2Map[value]) {
    console.log(value, arr2Map[value])
    result = result.concat(new Array(arr2Map[value]).fill(value))
  }
}
result = result.concat(leave.sort())
console.log(result)

